package plateform

import (
	"crypto/sha1"
	"encoding/hex"
	"sort"
	"strings"

	"github.com/gin-gonic/gin"
)

// 接入验证
func Index(c *gin.Context, msg string, data interface{}) {

	var signature = c.GetString("signature")
	var timestamp = c.GetString("timestamp")
	var nonce = c.GetString("nonce")
	var echostr = c.GetString("echostr")
	var token = "token-centre"

	var s = []string{token, timestamp, nonce}
	sort.Strings(s)

	var str = strings.Join(s, "")

	var h = sha1.New()
	h.Write([]byte(str))
	var hash = hex.EncodeToString(h.Sum(nil))

	if hash == signature {
		c.Writer.WriteString(echostr)
	}

}
